package com.ihr360.excel.vo;


import com.google.common.collect.Lists;
import com.ihr360.commons.exception.Ihr360Exception;
import com.ihr360.excel.entity.CorrectSpreadsheetRowEntity;

import java.io.ByteArrayInputStream;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * 最终导入需要的请求对象
 */
public class ImportRequest<T extends Serializable> implements Serializable {

    /**
     * 正常数据
     */
    private List<CorrectSpreadsheetRowEntity> correctDatas;

    /**
     * 业务校验产生的数据
     */
    private byte[] convertResult;

    /**
     * 自定义参数
     */
    private Map<String, Object> extraParams;


    public List<T> getConvertResultList() {
        if (convertResult == null) {
            return Lists.newArrayList();
        }
        List<T> result = null;
        try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(convertResult);
             ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream)) {
            result = (List<T>) objectInputStream.readObject();
        } catch (Exception e) {
            throw new Ihr360Exception(null, "导入失败，数据转换异常！");
        }
        return result;
    }


    /**
     * 需要导入的表头
     */
    private List<String> importHeaders;
    

    public List<CorrectSpreadsheetRowEntity> getCorrectDatas() {
        return correctDatas;
    }

    public void setCorrectDatas(List<CorrectSpreadsheetRowEntity> correctDatas) {
        this.correctDatas = correctDatas;
    }

    public byte[] getConvertResult() {
        return convertResult;
    }

    public void setConvertResult(byte[] convertResult) {
        this.convertResult = convertResult;
    }

    public List<String> getImportHeaders() {
        return importHeaders;
    }

    public void setImportHeaders(List<String> importHeaders) {
        this.importHeaders = importHeaders;
    }

    public Map<String, Object> getExtraParams() {
        return extraParams;
    }

    public void setExtraParams(Map<String, Object> extraParams) {
        this.extraParams = extraParams;
    }
}
